package org.nfyszny.zzzs.modules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.nfyszny.zzzs.modules.entity.ZzzsDosingManagement;

import org.nfyszny.zzzs.modules.mapper.ZzzsDosingManagementMapper;
import org.nfyszny.zzzs.modules.service.IZzzsDosingManagementService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 打药管理
 * @Author: jeecg-boot
 * @Date: 2022-11-10
 * @Version: V1.0
 */
@Service
public class ZzzsDosingManagementServiceImpl extends ServiceImpl<ZzzsDosingManagementMapper, ZzzsDosingManagement> implements IZzzsDosingManagementService {

    @Override
    public IPage<ZzzsDosingManagement> pageList(Page<ZzzsDosingManagement> page, QueryWrapper<ZzzsDosingManagement> queryWrapper) {
        Page<ZzzsDosingManagement> pageList = this.page(page, queryWrapper);

        List<ZzzsDosingManagement> records = pageList.getRecords();
        //根据state变成boolean类型值方便页面渲染
        pageList.setRecords(records.stream().map(item -> {
            item.setStatusBoolean(item.getStatus() == 1);
            return item;
        }).collect(Collectors.toList()));
        return pageList;
    }

    @Override
    public void switchStatus(String id, Integer status) {
        ZzzsDosingManagement management = new ZzzsDosingManagement();
        management.setStatus(status);
        management.setId(id);
        baseMapper.updateById(management);
    }
}
